﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using FbKPI.Model;
using FbKPI.Facade;


namespace FBKPI.Forms
{
    public partial class AssignmentKPI : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               

              

            }
        }

        protected override void OnLoad(EventArgs e)
        {
            KPIAssignmentFaced fc = new KPIAssignmentFaced();
            hfIdAssign.Value = Context.Request.Params["KpiID"];
            if (hfIdAssign.Value != "")
            {
                KPI objKPI = new KPIFacade().GetKPIByID(Convert.ToInt16(hfIdAssign.Value));
                if (objKPI != null)
                {
                    lblKPI.Text = objKPI.Description;
                    GroupKPI objGroup = new GroupKPIFacade().GetGroupKPIByID(objKPI.GroupKPI.ID);
                    if (objGroup != null)
                        //lblKPI.Text = objGroup.Description;
                        lblGroup.Text = objGroup.Description;

                    CategoryKPI objCategory = new CategoryKPIFacade().GetCategoryKPIByID(objKPI.CategoryKPI.ID);
                    if (objCategory != null)
                        //lblKPI.Text = lblKPI.Text + " > " + objCategory.Description;
                        lblCategory.Text = objCategory.Description;

                    TypeKPI objType = new TypeKPIFacade().GetTypeKPIByID(objKPI.TypeKPI.ID);
                    if (objType != null)
                        //lblKPI.Text = lblKPI.Text + " > " + objType.Description;
                        lblType.Text = objType.Description;

                    SubTypeKPI objSub = new SubTypeKPIFacade().GetSubTypeKPIByID(objKPI.SubTypeKPI.ID);
                    if (objSub != null)
                        //lblKPI.Text = lblKPI.Text + " > " + objSub.Description;
                        lblSub.Text = objSub.Description;

                    //lblKPI.Text = lblKPI.Text + " > " + objKPI.Description;


                }

                List<KPIAssignmentBy> list = fc.GetByKpiAssignmentByID(Convert.ToInt32(hfIdAssign.Value));
                int groupIDsatu = 1;
                int groupIDdua = 6;

                foreach (KPIAssignmentBy data in list)
                {
                    groupIDsatu = data.GroupID;
                }

                ddlAssigment.SelectedValue = groupIDsatu.ToString();

                list = fc.GetByKpiAssignmentByIDDua(Convert.ToInt32(hfIdAssign.Value));
                foreach (KPIAssignmentBy data in list)
                {
                    groupIDdua = data.GroupID;
                }

                ddlAssignmentDua.SelectedValue = groupIDdua.ToString();

            }


            hfIdDetail.Value = fc.CountKPIAssignmentBy(Convert.ToInt32(hfIdAssign.Value));
            //hfIdDetailRgmType.Value = fc.CountKPIAssignmentRgmType(Convert.ToInt32(hfId.Value));
            //hfIdDetailRgm.Value = fc.CountKPIAssignmentRgm(Convert.ToInt32(hfId.Value));
            //hfIdDetailBranch.Value = fc.CountKPIAssignmentBranch(Convert.ToInt32(hfId.Value));

            hfIdDetailDua.Value = fc.CountKPIAssignmentByDua(Convert.ToInt32(hfIdAssign.Value));
        }
    }
}